# Contributor: Pedro Filipe <xpecex@outlook.com>
# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: V.Krishn <vkrishn4@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=varnish
pkgver=7.4.2
pkgrel=0
pkgdesc="High-performance HTTP accelerator"
url="https://www.varnish-cache.org/"
arch="all"
license="BSD-2-Clause"
depends="gcc libc-dev libgcc"
makedepends="ncurses-dev libedit-dev py3-docutils
	linux-headers pcre2-dev libunwind-dev py3-sphinx"
install="$pkgname.pre-install"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc $pkgname-libs $pkgname-openrc"
pkgusers="varnish"
pkggroups="varnish"

source="https://varnish-cache.org/_downloads/varnish-$pkgver.tgz
	varnishd.initd
	varnishd.confd
	varnishlog.initd
	varnishlog.confd
	varnishncsa.initd
	varnishncsa.confd
	varnishd.logrotate
	varnishreload-$pkgver::https://github.com/varnishcache/pkg-varnish-cache/raw/35cba4e219b135b637bfd4fb27d98d548f21c20e/systemd/varnishreload"

case "$CARCH" in
	ppc64le) options="$options !check";; # tests fail
esac

# secfixes:
#   7.4.2-r0:
#     - CVE-2023-44487 VSV00013
#   7.2.1-r0:
#     - CVE-2022-45059 VSV00010
#     - CVE-2022-45060 VSV00011
#   7.0.3-r0:
#     - CVE-2022-38150
#   7.0.2-r0:
#     - CVE-2022-23959
#   6.6.1-r0:
#     - CVE-2021-36740
#   6.2.1-r0:
#     - CVE-2019-15892
#   5.2.1-r0:
#     - CVE-2017-8807
#   5.1.3-r0:
#     - CVE-2017-12425

build() {
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var/lib \
		--with-unwind \
		--without-jemalloc
	make
}

check() {
	make check -k VERBOSE=1
}

package() {
	make DESTDIR="$pkgdir" install

	local i; for i in $source; do
		case $i in
		*.initd) install -Dm755 "$srcdir/$i" \
				"$pkgdir/etc/init.d/${i%.*}" ;;
		*.confd) install -Dm644 "$srcdir/$i" \
				"$pkgdir/etc/conf.d/${i%.*}" ;;
		esac
	done
	install -Dm644 "$srcdir"/varnishd.logrotate \
		"$pkgdir"/etc/logrotate.d/varnishd
	install -d -o varnish -g varnish -m750 \
		"$pkgdir"/var/cache/varnish \
		"$pkgdir"/var/log/varnish \
		"$pkgdir"/var/lib/varnish
	install -d -o root -g varnish -m750 "$pkgdir"/etc/varnish
	install -m755 "$srcdir"/varnishreload-$pkgver "$pkgdir"/usr/bin/varnishreload
}

libs() {
	pkgdesc="Libraries for varnish"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.so.* "$subpkgdir"/usr/lib/
}

sha512sums="
acd61a852ac7d66b268ab831d3a771d7a063a6a257b5e7c25c5a2ec9bccefa845279b9bd5fc85dd0b4f1d56da59164a13149355d1e6187e71ad76463687f7971  varnish-7.4.2.tgz
be449f7cab645f7e2db49f00992aaec254423bb90d4cabdfbf21b272871907420e30e07c0cc46562565739e9a226ce142abc274d99b9418c57ce359ed4be8c19  varnishd.initd
494431a4cf37c5bbd0d533a08f0bc27ef58b66be7d82f78b3ccbc343368f4a159f9b76a7a5d4271dd16fe5e3b7bc47dfc828d0c821ffb5343dfc62c08e29f506  varnishd.confd
c67a7898f40849989edcbe74e1a418e196f48e178ca30126bc13db226e4f4c2c2ba74d9d0650ef68ed88732917fc06b80ef1f62c2d9d2c14a89f26fd25aed0f7  varnishlog.initd
88fe9b545a2b25d6e6e45f1cfecbeca5f503bc1fbe95856386e568edee41b487b162cddceba8cb152b0a37d8d96635a76c0715fc69d87d6c667ac403ebae0bb7  varnishlog.confd
e0b7d67bbd710f0a17b77837c581f128e6b746eff2b12e81d03d1ad040037e95bb00fb8007d89bc6dab18cfa659456078f310ac268f104774ef85ad068efecca  varnishncsa.initd
a5426ff66b89d2afb6273f05e4117b3eec5ce0162a624d52c92b418960f72e58bd01224165613221af76ec241bd98e1eb985b2ef7b83a5b615e9ece67234dcc8  varnishncsa.confd
51cc6d46ff7439de93977ab87dfb0af399458c1e446475696f73342ae7a0c1a8ca8fc6e79e593659f1af30716a5f8a1ee5e3b1f5e7b35df40b45d47e7b0f2ffd  varnishd.logrotate
282049f4d9ce2f64a3419678368e0933882e6bf959693df2125aa85e0fc280c59e0d42f830107e619d4760d01cc84e33dcf6b687a1ae9b40168f9c0a90c5d769  varnishreload-7.4.2
"
